﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using NUnit.Framework;
using Farigola.Engine.Factories;

namespace Farigola.Engine.TestUnit
{
     [TestFixture]
    public class EngineTestUnit
    {
         // [SetUp]
         // [TearDown]

         [Test]
         public void CreateEngineInitNotDone()
         {
             Engine engine = new Engine();
             Assert.IsNotNull(engine, "The engine should be created.");
             Assert.IsFalse(engine.IsInitDone, "The init of the engine should not done.");
         }

         [Test]
         public void CreateEngineInit()
         {
             Engine engine = new Engine();

             bool res= engine.Init();
             Assert.IsTrue(res, "The init of the engine should return ok.");
             Assert.IsTrue(engine.IsInitDone, "The init of the engine should be done.");
         }

         [Test]
         public void CreateEngineInitCheckInternal()
         {
             Engine engine = new Engine();

             engine.Init();
             bool res= engine.CheckInternal();
             Assert.IsTrue(res, "The CheckInternal of the engine should return ok.");
         }

   	    [Test]
	    public void CreateEngineWorkspaceAndProjectAreNull() {
            Engine engine = new Engine();
				
		    // the core is not init, no workspace
		    Workspace wksp= engine.GetWorkspace();
		    Assert.IsNull(wksp, "The workspace of the Engine should be null.");
		
		    // the core is not init, no active project
		    Project prj= engine.GetActiveProject();
		    Assert.IsNull(prj, "The active project of the (workspace)Engine should be null.");
	    }
	
	    /**
	     * try to init the engine 2 tomes, not possible.
	     */
	    [Test]
	    public void InitEngine2TimesWrong() {
            Engine engine = new Engine();
		
		    // init the core, create the factory, the workspace
		    bool res= engine.Init();		
		    Assert.IsTrue(res, "The init of the core should be right.");
		
		    // get the wokspace
		    Workspace wksp= engine.GetWorkspace();
		    Assert.IsNotNull(wksp, "The workspace should be present in the core after an init.");
		
		    // can't init again the core, return an error
		    res= engine.Init();
		
	        Assert.IsFalse(res, "Can't init 2 times the core.");
		
	        // no active project present in the workspace
		    Project prj= engine.GetActiveProject();
		    Assert.IsNull(prj,"The azctive project of the (workspace)Engine should be null.");	    
	    }

	    [Test]
	    public void testEngineCheckInternal() {
            Engine engine = EngineCommonTestUnit.CreateInitEngine();
		
		    // check the Engine internal content, after init 
		    bool res= engine.CheckInternal();
		    Assert.IsTrue(res,"The check internal should return true.");
	    }

        [Test]
	    public void testCreateProject() {
            Engine engine = EngineCommonTestUnit.CreateInitEngine();
            Workspace wksp = engine.GetWorkspace();

		    String prjName= "prj";
		
		    // create a project, the first becomes the active one
		    Project prj= wksp.CreateActiveProject(prjName);
		    Assert.IsNotNull(prj,"The active project should be created.");
		
		    // get the active project
		    prj= engine.GetActiveProject();
		    Assert.IsNotNull(prj,"The active project should be present.");

		    // create a new active project, not possible, already exists
            prj = wksp.CreateActiveProject(prjName);
		    Assert.IsNull(prj, "Can't create a new active project, already present.");
		
		    // get the active project, still present
		    prj= engine.GetActiveProject();
		    Assert.IsNotNull(prj, "The active project should be still present.");
	    }
    }
}
